home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.accessibility.AccessibleContext;
- import com.sun.java.swing.event.EventListenerList;
- import com.sun.java.swing.event.ListSelectionEvent;
- import com.sun.java.swing.event.ListSelectionListener;
- import com.sun.java.swing.plaf.ListUI;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Insets;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.util.Vector;
-
- public class JList extends JComponent implements Scrollable, Accessible {
- private int fixedCellWidth;
- private int fixedCellHeight;
- private Object prototypeCellValue;
- private int visibleRowCount;
- private Color selectionForeground;
- private Color selectionBackground;
- private ListSelectionModel selectionModel;
- private ListModel dataModel;
- private ListCellRenderer cellRenderer;
- private ListSelectionListener selectionListener;
- static Class class$com$sun$java$swing$event$ListSelectionListener;
-
- public JList() {
- this((ListModel)(new 1()));
- }
-
- public JList(Object[] listData) {
- this((ListModel)(new 2(listData)));
- }
-
- public JList(ListModel dataModel) {
- this.fixedCellWidth = -1;
- this.fixedCellHeight = -1;
- this.visibleRowCount = 8;
- if (dataModel == null) {
- throw new IllegalArgumentException("dataModel must be non null");
- } else {
- this.dataModel = dataModel;
- this.selectionModel = this.createSelectionModel();
- ((JComponent)this).setAutoscrolls(true);
- this.updateUI();
- }
- }
-
- public JList(Vector listData) {
- this((ListModel)(new 3(listData)));
- }
-
- public void addListSelectionListener(ListSelectionListener listener) {
- if (this.selectionListener == null) {
- this.selectionListener = new 4(this);
- this.getSelectionModel().addListSelectionListener(this.selectionListener);
- }
-
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$com$sun$java$swing$event$ListSelectionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ListSelectionListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$ListSelectionListener = var10001;
- }
-
- var10000.add(var10001, listener);
- }
-
- public void addSelectionInterval(int anchor, int lead) {
- this.getSelectionModel().addSelectionInterval(anchor, lead);
- }
-
- public void clearSelection() {
- this.getSelectionModel().clearSelection();
- }
-
- protected ListSelectionModel createSelectionModel() {
- return new DefaultListSelectionModel();
- }
-
- public void ensureIndexIsVisible(int index) {
- Rectangle cellBounds = this.getCellBounds(index, index);
- if (cellBounds != null) {
- ((JComponent)this).scrollRectToVisible(cellBounds);
- }
-
- }
-
- protected void fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) {
- Object[] listeners = super.listenerList.getListenerList();
- ListSelectionEvent e = null;
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$com$sun$java$swing$event$ListSelectionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ListSelectionListener");
- } catch (ClassNotFoundException var7) {
- throw new NoClassDefFoundError(((Throwable)var7).getMessage());
- }
-
- class$com$sun$java$swing$event$ListSelectionListener = var10001;
- }
-
- if (var10000 == var10001) {
- if (e == null) {
- e = new ListSelectionEvent(this, firstIndex, lastIndex, isAdjusting);
- }
-
- ((ListSelectionListener)listeners[i + 1]).valueChanged(e);
- }
- }
-
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJList(this);
- }
-
- return super.accessibleContext;
- }
-
- public int getAnchorSelectionIndex() {
- return this.getSelectionModel().getAnchorSelectionIndex();
- }
-
- public Rectangle getCellBounds(int index1, int index2) {
- ListUI ui = this.getUI();
- return ui != null ? ui.getCellBounds(this, index1, index2) : null;
- }
-
- public ListCellRenderer getCellRenderer() {
- return this.cellRenderer;
- }
-
- public int getFirstVisibleIndex() {
- Point visibleUL = ((JComponent)this).getVisibleRect().getLocation();
- return this.locationToIndex(visibleUL);
- }
-
- public int getFixedCellHeight() {
- return this.fixedCellHeight;
- }
-
- public int getFixedCellWidth() {
- return this.fixedCellWidth;
- }
-
- public int getLastVisibleIndex() {
- Rectangle r = ((JComponent)this).getVisibleRect();
- Point visibleLR = new Point(r.x + r.width - 1, r.y + r.height - 1);
- return this.locationToIndex(visibleLR);
- }
-
- public int getLeadSelectionIndex() {
- return this.getSelectionModel().getLeadSelectionIndex();
- }
-
- public int getMaxSelectionIndex() {
- return this.getSelectionModel().getMaxSelectionIndex();
- }
-
- public int getMinSelectionIndex() {
- return this.getSelectionModel().getMinSelectionIndex();
- }
-
- public ListModel getModel() {
- return this.dataModel;
- }
-
- public Dimension getPreferredScrollableViewportSize() {
- Insets insets = ((JComponent)this).getInsets();
- int dx = insets.left + insets.right;
- int dy = insets.top + insets.bottom;
- int visibleRowCount = this.getVisibleRowCount();
- int fixedCellWidth = this.getFixedCellWidth();
- int fixedCellHeight = this.getFixedCellHeight();
- if (fixedCellWidth > 0 && fixedCellHeight > 0) {
- int width = fixedCellWidth + dx;
- int height = visibleRowCount * fixedCellHeight + dy;
- return new Dimension(width, height);
- } else if (this.getModel().getSize() > 0) {
- int width = ((JComponent)this).getPreferredSize().width;
- Rectangle r = this.getCellBounds(0, 0);
- int height = visibleRowCount * r.height + dy;
- return new Dimension(width, height);
- } else {
- fixedCellWidth = fixedCellWidth > 0 ? fixedCellWidth : 256;
- fixedCellHeight = fixedCellHeight > 0 ? fixedCellHeight : 16;
- return new Dimension(fixedCellWidth, fixedCellHeight * visibleRowCount);
- }
- }
-
- public Object getPrototypeCellValue() {
- return this.prototypeCellValue;
- }
-
- public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
- return orientation == 1 ? visibleRect.height : visibleRect.width;
- }
-
- public boolean getScrollableTracksViewportHeight() {
- return false;
- }
-
- public boolean getScrollableTracksViewportWidth() {
- return false;
- }
-
- public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
- if (orientation == 0) {
- return 1;
- } else {
- int row = this.getFirstVisibleIndex();
- if (row == -1) {
- return 0;
- } else if (direction > 0) {
- Rectangle r = this.getCellBounds(row, row);
- return r == null ? 0 : r.height - (visibleRect.y - r.y);
- } else {
- Rectangle r = this.getCellBounds(row, row);
- if (r.y == visibleRect.y && row == 0) {
- return 0;
- } else if (r.y == visibleRect.y) {
- Rectangle prevR = this.getCellBounds(row - 1, row - 1);
- return prevR == null ? 0 : prevR.height;
- } else {
- return visibleRect.y - r.y;
- }
- }
- }
- }
-
- public int getSelectedIndex() {
- return this.getMinSelectionIndex();
- }
-
- public int[] getSelectedIndices() {
- ListSelectionModel sm = this.getSelectionModel();
- int iMin = sm.getMinSelectionIndex();
- int iMax = sm.getMaxSelectionIndex();
- if (iMin >= 0 && iMax >= 0) {
- int[] rvTmp = new int[1 + (iMax - iMin)];
- int n = 0;
-
- for(int i = iMin; i <= iMax; ++i) {
- if (sm.isSelectedIndex(i)) {
- rvTmp[n++] = i;
- }
- }
-
- int[] rv = new int[n];
- System.arraycopy(rvTmp, 0, rv, 0, n);
- return rv;
- } else {
- return new int[0];
- }
- }
-
- public Object getSelectedValue() {
- int i = this.getMinSelectionIndex();
- return i == -1 ? null : this.getModel().getElementAt(i);
- }
-
- public Object[] getSelectedValues() {
- ListSelectionModel sm = this.getSelectionModel();
- ListModel dm = this.getModel();
- int iMin = sm.getMinSelectionIndex();
- int iMax = sm.getMaxSelectionIndex();
- if (iMin >= 0 && iMax >= 0) {
- Object[] rvTmp = new Object[1 + (iMax - iMin)];
- int n = 0;
-
- for(int i = iMin; i <= iMax; ++i) {
- if (sm.isSelectedIndex(i)) {
- rvTmp[n++] = dm.getElementAt(i);
- }
- }
-
- Object[] rv = new Object[n];
- System.arraycopy(rvTmp, 0, rv, 0, n);
- return rv;
- } else {
- return new Object[0];
- }
- }
-
- public Color getSelectionBackground() {
- return this.selectionBackground;
- }
-
- public Color getSelectionForeground() {
- return this.selectionForeground;
- }
-
- public int getSelectionMode() {
- return this.getSelectionModel().getSelectionMode();
- }
-
- public ListSelectionModel getSelectionModel() {
- return this.selectionModel;
- }
-
- public ListUI getUI() {
- return (ListUI)super.ui;
- }
-
- public String getUIClassID() {
- return "ListUI";
- }
-
- public boolean getValueIsAdjusting() {
- return this.getSelectionModel().getValueIsAdjusting();
- }
-
- public int getVisibleRowCount() {
- return this.visibleRowCount;
- }
-
- public Point indexToLocation(int index) {
- ListUI ui = this.getUI();
- return ui != null ? ui.indexToLocation(this, index) : null;
- }
-
- public boolean isOpaque() {
- return true;
- }
-
- public boolean isSelectedIndex(int index) {
- return this.getSelectionModel().isSelectedIndex(index);
- }
-
- public boolean isSelectionEmpty() {
- return this.getSelectionModel().isSelectionEmpty();
- }
-
- public int locationToIndex(Point location) {
- ListUI ui = this.getUI();
- return ui != null ? ui.locationToIndex(this, location) : -1;
- }
-
- public void removeListSelectionListener(ListSelectionListener listener) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$com$sun$java$swing$event$ListSelectionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ListSelectionListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$ListSelectionListener = var10001;
- }
-
- var10000.remove(var10001, listener);
- }
-
- public void removeSelectionInterval(int index0, int index1) {
- this.getSelectionModel().removeSelectionInterval(index0, index1);
- }
-
- public void setCellRenderer(ListCellRenderer cellRenderer) {
- ListCellRenderer oldValue = this.cellRenderer;
- this.cellRenderer = cellRenderer;
- if (cellRenderer != null && !cellRenderer.equals(oldValue)) {
- this.updateFixedCellSize();
- }
-
- ((JComponent)this).firePropertyChange("cellRenderer", oldValue, cellRenderer);
- }
-
- public void setFixedCellHeight(int height) {
- int oldValue = this.fixedCellHeight;
- this.fixedCellHeight = height;
- ((JComponent)this).firePropertyChange("fixedCellHeight", oldValue, this.fixedCellHeight);
- }
-
- public void setFixedCellWidth(int width) {
- int oldValue = this.fixedCellWidth;
- this.fixedCellWidth = width;
- ((JComponent)this).firePropertyChange("fixedCellWidth", oldValue, this.fixedCellWidth);
- }
-
- public void setListData(Object[] listData) {
- this.setModel(new 5(listData));
- }
-
- public void setListData(Vector listData) {
- this.setModel(new 6(listData));
- }
-
- public void setModel(ListModel model) {
- ListModel oldValue = this.dataModel;
- this.dataModel = model;
- ((JComponent)this).firePropertyChange("model", oldValue, this.dataModel);
- this.clearSelection();
- }
-
- public void setPrototypeCellValue(Object prototypeCellValue) {
- Object oldValue = this.prototypeCellValue;
- this.prototypeCellValue = prototypeCellValue;
- if (prototypeCellValue != null && !prototypeCellValue.equals(oldValue)) {
- this.updateFixedCellSize();
- }
-
- ((JComponent)this).firePropertyChange("prototypeCellValue", oldValue, prototypeCellValue);
- }
-
- public void setSelectedIndex(int index) {
- this.getSelectionModel().setSelectionInterval(index, index);
- }
-
- public void setSelectedIndices(int[] indices) {
- ListSelectionModel sm = this.getSelectionModel();
- sm.clearSelection();
-
- for(int i = 0; i < indices.length; ++i) {
- sm.addSelectionInterval(indices[i], indices[i]);
- }
-
- }
-
- public void setSelectedValue(Object anObject, boolean shouldScroll) {
- if (anObject == null) {
- this.setSelectedIndex(-1);
- } else if (!anObject.equals(this.getSelectedValue())) {
- ListModel dm = this.getModel();
- int i = 0;
-
- for(int c = dm.getSize(); i < c; ++i) {
- if (anObject.equals(dm.getElementAt(i))) {
- this.setSelectedIndex(i);
- if (shouldScroll) {
- this.ensureIndexIsVisible(i);
- }
-
- ((Component)this).repaint();
- return;
- }
- }
-
- this.setSelectedIndex(-1);
- }
-
- ((Component)this).repaint();
- }
-
- public void setSelectionBackground(Color selectionBackground) {
- Color oldValue = this.selectionBackground;
- this.selectionBackground = selectionBackground;
- ((JComponent)this).firePropertyChange("selectionBackground", oldValue, selectionBackground);
- }
-
- public void setSelectionForeground(Color selectionForeground) {
- Color oldValue = this.selectionForeground;
- this.selectionForeground = selectionForeground;
- ((JComponent)this).firePropertyChange("selectionForeground", oldValue, selectionForeground);
- }
-
- public void setSelectionInterval(int anchor, int lead) {
- this.getSelectionModel().setSelectionInterval(anchor, lead);
- }
-
- public void setSelectionMode(int selectionMode) {
- this.getSelectionModel().setSelectionMode(selectionMode);
- }
-
- public void setSelectionModel(ListSelectionModel selectionModel) {
- if (selectionModel == null) {
- throw new IllegalArgumentException("selectionModel must be non null");
- } else {
- if (this.selectionListener != null) {
- this.selectionModel.removeListSelectionListener(this.selectionListener);
- selectionModel.addListSelectionListener(this.selectionListener);
- }
-
- ListSelectionModel oldValue = this.selectionModel;
- this.selectionModel = selectionModel;
- ((JComponent)this).firePropertyChange("selectionModel", oldValue, selectionModel);
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleSelection", new Boolean(false), new Boolean(true));
- }
-
- }
- }
-
- public void setUI(ListUI ui) {
- super.setUI(ui);
- }
-
- public void setValueIsAdjusting(boolean b) {
- this.getSelectionModel().setValueIsAdjusting(b);
- }
-
- public void setVisibleRowCount(int visibleRowCount) {
- int oldValue = this.visibleRowCount;
- this.visibleRowCount = Math.max(0, visibleRowCount);
- ((JComponent)this).firePropertyChange("visibleRowCount", oldValue, visibleRowCount);
- }
-
- private void updateFixedCellSize() {
- ListCellRenderer cr = this.getCellRenderer();
- Object value = this.getPrototypeCellValue();
- if (cr != null && value != null) {
- Component c = cr.getListCellRendererComponent(this, value, 0, false, false);
- Font f = c.getFont();
- c.setFont(((Component)this).getFont());
- Dimension d = c.getPreferredSize();
- this.fixedCellWidth = d.width;
- this.fixedCellHeight = d.height;
- c.setFont(f);
- }
-
- }
-
- public void updateUI() {
- this.setUI((ListUI)UIManager.getUI(this));
- ((Container)this).invalidate();
- }
-
- static ListSelectionModel access$selectionModel(JList var0) {
- return var0.selectionModel;
- }
- }
-